package com.jie.jie.tuisong;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import com.jaydenxiao.common.baseapp.AppManager;
import com.jaydenxiao.common.commonutils.LogUtils;
import com.jaydenxiao.common.commonutils.ToastUitl;
import com.jaydenxiao.common.v.dialog.CommonFinishDialog;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Administrator on 2017/2/3.
 */

public class MyReceiver extends BroadcastReceiver {

    private String result;

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = "cn.jpush.android.intent.MESSAGE_RECEIVED";
        if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(action)) {
            Bundle extras = intent.getExtras();
            if (null == extras) {
                LogUtils.loge("bundle为空");
                return;
            }
            String title = extras.getString(JPushInterface.EXTRA_TITLE);
            String message = extras.getString(JPushInterface.EXTRA_MESSAGE);
            String extraJson = extras.getString(JPushInterface.EXTRA_EXTRA);
            LogUtils.loge("Message title : " + title);
            LogUtils.loge("Message content : " + message);
            LogUtils.loge("Message extraJson : " + extraJson);
            result = extras.getString(JPushInterface.EXTRA_ALERT);
            LogUtils.loge(result);
            if (result != null && !"".equals(result)) {

                if (result.equals("账号在别处登录")) {
                    new CommonFinishDialog.Builder(context)
                            .setMessage(result)
                            .setTitle("温馨提示")
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                    AppManager.getAppManager().finishAllActivity();
                                }
                            }).create();

                }
            }
        }
        LogUtils.loge("接受到广播");

        ToastUitl.showShort("接受到广播");
    }
}
